/**
 * 表单验证工具函数
 */

// 验证手机号
export const validatePhone = (phone: string): boolean => {
  const reg = /^1[3-9]\d{9}$/;
  return reg.test(phone);
};

// 验证密码(6-20位)
export const validatePassword = (password: string): boolean => {
  return password.length >= 6 && password.length <= 20;
};

// 验证验证码(6位数字)
export const validateCode = (code: string): boolean => {
  const reg = /^\d{6}$/;
  return reg.test(code);
};

// 验证昵称(2-20个字符)
export const validateNickname = (nickname: string): boolean => {
  return nickname.length >= 2 && nickname.length <= 20;
};

// 验证地址
export const validateAddress = (address: string): boolean => {
  return address.length >= 5 && address.length <= 200;
};

// 通用非空验证
export const validateRequired = (value: any): boolean => {
  if (typeof value === 'string') {
    return value.trim().length > 0;
  }
  return value !== null && value !== undefined;
};